package com.kgcx.coupon.controller;

import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.domain.CouponDetail;
import com.kgcx.coupon.domain.PullConfig;
import com.kgcx.coupon.domain.PullRule;
import com.kgcx.coupon.dto.ConfigDto;

import com.kgcx.coupon.service.CouponDetailService;
import com.kgcx.coupon.service.PullConfigService;
import com.kgcx.coupon.service.PullRuleService;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 何凯
 * @version 0.1
 * @description
 * @time 2017/12/15 18:16
 * @since 0.1
 */
@Api(description = "拉新配置", tags = "拉新配置接口")
@RestController
@RequestMapping("coupon/v1/pullConfig")
public class PullConfigController extends BaseController{
	@Resource
	private CouponDetailService couponDetailService;
	@Resource
	private PullConfigService pullConfigService;
	@Resource
	private PullRuleService pullRuleService;

	/**
	 * 查询拉新策略配置
	 * @param kid
	 * @return
	 */
	@ApiOperation(value = "拉取拉新配置", httpMethod = "GET", notes = "拉取拉新配置接口")
	@GetMapping(value = "get")
	public ReturnData<PullConfig> getPullConfig() {
		PullConfig pullConfig = new PullConfig();
		pullConfig = pullConfigService.selectPullConfigNoStatus();
		if (null != pullConfig) {
			List<CouponDetail> couponDetailList = couponDetailService.selectNewStrategy();
			pullConfig.setCouponDetailList(couponDetailList);
			List<PullRule> ruleList = pullRuleService.selectPullRuleByConfigId(pullConfig.getKid());
			pullConfig.setRuleList(ruleList);
		}
		ReturnData<PullConfig> response = new ReturnData<PullConfig>();
		response.setData(pullConfig);
		return response;
	}
	
	@ApiOperation(value = "添加拉新配置", httpMethod = "POST", notes = "添加拉新配置接口")
	@RequestMapping(value = "addPullConfig", method = RequestMethod.POST)
	public ReturnData<?> addPullConfig(@RequestBody ConfigDto configDto) {
		pullConfigService.saveConfig(configDto);
		return new ReturnData<>();
	}
	
	@ApiOperation(value = "修改拉新配置", httpMethod = "POST", notes = "修改拉新配置接口")
	@RequestMapping(value = "modifyPullConfig", method = RequestMethod.POST)
	public ReturnData<?> modifyPullConfig(@RequestBody ConfigDto configDto) {
		pullConfigService.modifyConfig(configDto);
		return new ReturnData<>();
	}
	
	
	
}
